/**
 * @description mongoose 连接数据库
 * @author 博文
 */

const mongoose = require('mongoose')

const url = 'mongodb://localhost:27017'
const dbName = 'testdb'

// 开始连接
mongoose.connect(`${url}/${dbName}`, {
    useNewUrlParser: true,
    useUnifiedTopology: true
})

// 连接对象
const db = mongoose.connection

db.on('error', err => {
    console.error('mongoose connect error', err);
})

db.once('open', () => {
    console.log('mongoose connect success');
})

module.exports = mongoose